#include "StdAfx.h"
#include "DrawWarpAffine.h"


CDrawWarpAffine::CDrawWarpAffine(void)
{
}


CDrawWarpAffine::~CDrawWarpAffine(void)
{
}
BEGIN_MESSAGE_MAP(CDrawWarpAffine, CDrawOpenCV)
	ON_WM_PAINT()
END_MESSAGE_MAP()


void CDrawWarpAffine::DealwithFrame()
{
	// TODO: Add your command handler code here
	if(m_pFrame == NULL)
	{			
		return ;
	}
	if(m_pShow != NULL)
	{
		cvReleaseImage(&m_pShow);
	}

	CvPoint2D32f srcTri[3], dstTri[3];
	CvMat* rot_mat  = cvCreateMat(2,3,CV_32FC1);
	CvMat* warp_mat = cvCreateMat(2,3,CV_32FC1);
	IplImage *src=0;

	src = cvCloneImage(m_pFrame);
	cvFlip(src);
	m_pShow = cvCloneImage(src);
	m_pShow->origin = m_pShow->origin;
	cvZero(m_pShow);

	//COMPUTE WARP MATRIX
	srcTri[0].x = 0;                          //src Top left
	srcTri[0].y = 0;
	srcTri[1].x = (float) src->width - 1;     //src Top right
	srcTri[1].y = 0;
	srcTri[2].x = 0;                          //src Bottom left
	srcTri[2].y = (float) src->height - 1;
	//- - - - - - - - - - - - - - -//
	dstTri[0].x = (float)(src->width*0.0);    //dst Top left
	dstTri[0].y = (float)(src->height*0.33);
	dstTri[1].x = (float)(src->width*0.85);   //dst Top right
	dstTri[1].y = (float)(src->height*0.25);
	dstTri[2].x = (float)(src->width*0.15);   //dst Bottom left
	dstTri[2].y = (float)(src->height*0.7);
	cvGetAffineTransform(srcTri,dstTri,warp_mat);
	cvWarpAffine(src,m_pShow,warp_mat);
	cvCopy(m_pShow,src);

	//COMPUTE ROTATION MATRIX
	CvPoint2D32f center = cvPoint2D32f(src->width/2,src->height/2);
	double angle = -50.0;
	double scale = 0.6;
	cv2DRotationMatrix(center,angle,scale,rot_mat);
	cvWarpAffine(src,m_pShow,rot_mat);

	cvReleaseImage(&src);

}